﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using OgilvyOne.Model;
using OgilvyOne.BLL;

public partial class admin_infomation_select : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            string tag = Request.Params["tag"];
            ListBox1.Items.Clear();
            CmsArticleTagBll catb = new CmsArticleTagBll();
            CmsArticleTagModel catm = new CmsArticleTagModel();
            IList ls = catb.GetTagList(catm);
            this.ListBox1.DataSource = ls;
            this.ListBox1.DataTextField = "TagName";
            this.ListBox1.DataValueField = "TagId";
            this.ListBox1.DataBind();
            this.Button5.Attributes.Add("onclick", "window.close()");
            if (tag != null && tag.Trim() != "")
            {
                string[] tags = tag.Split(',');
                for (int i = 0; i < tags.Length; i++)
                {
                    for(int j=0;j<ListBox1.Items.Count;j++)
                    {
                        string us = tags[i].ToString();
                        if (ListBox1.Items[j].Value.ToString()==us)
                        {
                            ListItem lit = new ListItem(ListBox1.Items[j].Text.ToString(), ListBox1.Items[j].Value.ToString());
                            ListBox2.Items.Add(lit);
                            ListBox1.Items.Remove(ListBox1.Items[j]);
                            ListBox2.SelectedIndex = -1;
                        }
                    }
                }
            }
            else
            {

            }
        }
    }
    //搜索按钮
    protected void Button3_Click(object sender, EventArgs e)
    {
        ListBox1.Items.Clear();
        CmsArticleTagBll catb = new CmsArticleTagBll();
        CmsArticleTagModel catm = new CmsArticleTagModel();
        if (TextBox1.Text != null && TextBox1.Text.ToString().Trim() != "")
        {
            catm.TagName = this.TextBox1.Text.ToString().Trim();
        }
        IList ls = catb.GetTagList(catm);
        this.ListBox1.DataSource = ls;
        this.ListBox1.DataTextField = "TagName";
        this.ListBox1.DataValueField = "TagId";
        this.ListBox1.DataBind();
    }
    //选择
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (ListBox1.SelectedIndex != -1)
        {
            ListBox2.Items.Add(ListBox1.SelectedItem);
            ListBox1.Items.Remove(ListBox1.SelectedItem);
            ListBox2.SelectedIndex = -1;
        }
        else
        {
            ListBox1.SelectedIndex = 0;
        }
    }
    //删除
    protected void Button2_Click(object sender, EventArgs e)
    {
        if (ListBox2.SelectedIndex != -1)
        {
            ListBox1.Items.Add(ListBox2.SelectedItem);
            ListBox2.Items.Remove(ListBox2.SelectedItem);
            ListBox1.SelectedIndex = -1;
        }
        else
        {
            ListBox2.SelectedIndex = 0;
        }
    }
    //确定
    protected void Button4_Click(object sender, EventArgs e)
    {
        //string ids = "";
        //string names = "";
        //bool bo = false;
        //foreach (ListItem i in ListBox2.Items)
        //{
        //        bo = true;
        //        names += i.Text.ToString().Trim()+",";
        //        ids += i.Value.ToString().Trim()+",";
        //}
        //if (bo)
        //{
        //    ids = ids.Substring(0, ids.LastIndexOf(","));
        //    names = names.Substring(0, names.LastIndexOf(","));
        //}
        //tid.Value = ids;
        //tname.Text = names;
    }
}
